package net.janeluo.rs.filter;


import javax.servlet.http.HttpSession;

import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionFilter;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.View;
import org.nutz.mvc.view.ServerRedirectView;

public class CheckUserSession implements ActionFilter {
    private String name;
    private String path;

    public CheckUserSession(String name, String path) {
        this.name = name;
        this.path = path;
    }

    public View match(ActionContext context) {
        String path2 = context.getPath();
        System.out.println(path2);
        HttpSession session = Mvcs.getHttpSession(false);
        if (path2.equals("/InitIndex") || path2.equals("/InitUserIndex") 
                || path2.equals("/Login") || path2.equals("/UserRegist") 
                || path2.equals("/checkUserExists") || path2.equals("/CheckUserPwd")) {
            return null;
        }
        if ((session == null) || (null == session.getAttribute(this.name))){
            return new ServerRedirectView(this.path);
        }
        return null;
    }
}
